# 通过datetime模块完成时间戳，datetime.datetime对象，格式化字符串三者之间的转换
import datetime
# datetime.datetime->str
now = datetime.datetime.now(tz=None)
print(now.strftime("%Y-%m-%d %H:%M:%S"))

# str->datetime.datetime
new = "2021-01-01 22:22:22"
print(datetime.datetime.strptime(new, "%Y-%m-%d %H:%M:%S"))

# datetime.datetime->timestamp
print(now.timestamp())

# timestamp->datetime.datetime
ts = now.timestamp()
print(datetime.datetime.fromtimestamp(ts, tz=None))




# 封装一个函数get_date（day_delta），如果传入的是-1，输出就是字符串日期2020-01-02
from datetime import datetime
from datetime import timedelta
def get_date(x):
    ys = now + timedelta(days=x)
    print(ys)
    return ys

get_date(-1)

